/*
 * User: rant
 * Date: May 2, 2007
 *
 *
 */
package laMalinche.agenda;

import laMalinche.rete.nodes.ActivatorNode;

import java.util.*;

/**
 *
 */
public class BasicAgenda implements Agenda {
	private List<ActivatorNode> newActions;

	public void addAction(ActivatorNode activatorNode) {
		newActions.add(activatorNode);
	}

	public void invoke() {
		List<ActivatorNode> newActions = getNewActions();
		List<ActivatorNode> workingActions = new ArrayList<ActivatorNode>();
        while (!workingActions.isEmpty() || !newActions.isEmpty()) {
			workingActions.addAll(newActions);
			newActions.clear();
            ActivatorNode activatorNode = getNextActivator(workingActions);
            workingActions.remove(activatorNode);
			invokeAcitvator(activatorNode);
		}
	}

	private ActivatorNode getNextActivator(final List<ActivatorNode> workingActions) {

        return null;
	}

	private void invokeAcitvator(ActivatorNode activatorNode) {
		activatorNode.updateActivatorConditions();
		if (activatorNode.isActive()) {
			activatorNode.activate();
		}
	}

	private List<ActivatorNode> getNewActions() {
		return newActions;
	}
}